<?php
//include("user/userlogincheck.php");
include("include/config.inc.php");
include("api/sms.php");

$id=$_REQUEST["id"];

$sql="SELECT * FROM ".tableprefix."goods where goods_id='$id'";
$result=$db->query($sql);
$row=$db->fetch_array($result);
$price=$row["book_down_payment"];
$pcode=$row["code"];
$db->free_result($result);

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){
	$smscode = $_POST['smscode'];
	$code = $_POST['code'];
	$pcode = $_POST['pcode'];
	$verify = $_SESSION['session_verify'];
	$sms = $_SESSION['session_smscode'];
	if($code==""){
		echo "<script>alert('请输入验证码！');history.back(-1);</script>";
		exit;
	}
	if($code<>$verify){
		echo "<script>alert('请输入正确的验证码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==""){
		echo "<script>alert('请输入手机短信动态码！');history.back(-1);</script>";
		exit;
	}
	if($smscode<>$sms){	
		echo "<script>alert('手机短信验证码输入不正确！');history.back(-1);</script>";
		exit;
	}else{
	$goods_id=$_POST["goods_id"];
	$ordername="订金";
	$nickname=$_POST["nickname"];
	$mobile=$_POST["mobile"];
	$payment=$_POST["payment"];
	$time=time();
	$ip=getIP();
	$paystate='0';
	
	$ap="";
  	$temp_x=$_POST["posTypeSelect"];
  	for($i=0;$i<count($temp_x);$i++){ 
  		$ap=$ap.$temp_x[$i].",";
		$a=$temp_x[$i];
		$sql="update ".tableprefix."datetime set flag='F' where date='$a' and code='$pcode'";
		$db->query($sql);		
  	}
  	$z=substr($ap,0,-1);//去除末尾单引号职位分类
	$orderinfo=$z;
	$amount=$price*$i;
	
	$sql="SELECT id FROM ".tableprefix."order order by id DESC limit 0,1;";
	$result=$db->query($sql);
	$s=$db->fetch_array($result);
	$orderid=$s["id"]+1000001;
	$orderNo='2'.date("ymdHis").$orderid;//业务编码+年的后2位+月+日+订单数(订单ID)[1 170515230101 1000001];
	$sql="insert into ".tableprefix."order(orderNo,userid,amount,goods_id,ordername,nickname,mobile,payment,orderinfo,createtime,ip,paystate)values('$orderNo','$userid','$amount','$goods_id','$ordername','$nickname','$mobile','$payment','$orderinfo','$time','$ip','0')";
	$db->query($sql);	
	if(!$db->error()){
		//$store_id=GetValueByKey(tablepre."goods","goods_id",$goods_id,"store_id");
		//$sql="select store_name,member_id from ".tablepre."store where store_id='$store_id'";
		//$result=$db->query($sql);
		//$row=$db->fetch_array($result);
		//$store_name=$row["store_name"];
		//$member_id=$row["member_id"];
		//$db->free_result($result);
		//$member_mobile=GetValueByKey(tablepre."member","member_id",$member_id,"member_mobile");
		//$name=$store_name;	
		//$content=$orderNo;
		//$smstype="placeorder";
		//$sms = new Sms();
		//$result = $sms->Send($member_mobile,$content,$smstype,$name);
		GotoPage('../pay/wxpay/deposit.php?orderNo='.$orderNo);
		exit;	
		}
	}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>订戏下单 - 订戏会</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=9,Chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="stylesheet" type="text/css" href="css/public.css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<link href="css/src/ui-choose.css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
	function get_mobile_code(){
        $.post('../user/sms.php', {mobile:jQuery.trim($('#mobile').val()),send_code:jQuery.trim($('#code').val()),smstype:jQuery.trim($('#smstype').val())}, function(msg) {
            alert(jQuery.trim(unescape(msg)));
			if(msg=='短信发送成功'){
				RemainTime();
			}
        });
	};
	var iTime = 59;
	var Account;
	function RemainTime(){
		document.getElementById('zphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取手机验证码';
				iTime = 59;
				document.getElementById('zphone').disabled = false;
			}else{
				Account = setTimeout("RemainTime()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zphone').value = sTime;
	}	
</script>
</head>

<body>
<div class="head-nav">
	<div class="head-left"><a href="#1"><div class="back">返回</div></a></div>
	<div class="head-center">演出信息发布</div>
	<div class="head-right"><a href="#"><div class="shuoming"></div></a></div>
</div>
<form action="" method="post" name="publishForm" id="publishForm">
<input name="todo" type="hidden" value="todo">
<input name="goods_id" type="hidden" value="<?php echo $id;?>">
<input name="pcode" type="hidden" value="<?php echo $pcode;?>">
<input name="smstype" id="smstype" type="hidden" value="mobilecheck">
<div class="mod-form">
	<div class="order-box">
		<div class="form-goods">
			<div class="order-img"><img src="<?php echo $row["goods_image"];?>"></div>
			<div class="order-price">
				<h1><?php echo $row["goods_name"];?></h1>
				<p>演出费用：<font color="#FF0000"><?php echo $row["goods_price"];?></font>元</p>
				<p>预交订金：<font color="#FF0000"><?php echo $row["book_down_payment"];?></font>元</p>
			</div>		
		</div>
	</div>
	<div class="order-box">
		<div class="form-date" style="background:#FFFFFF;">
			<h1>选择演出日期</h1>
			<ul>
				<li>日</li>
				<li>一</li>
				<li>二</li>
				<li>三</li>
				<li>四</li>
				<li>五</li>
				<li>六</li>
			</ul>
			<span>2017年10月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option></option>
				<option></option>
			<?php for($d=1;$d<=31;$d++){
			if($d<=9){
			$dd="0".$d;
			}else{
			$dd=$d;
			}
			?>
			<?php
			$selectdate="2017-10-".$dd;
			$sql = "select count(*) as count from ".tableprefix."datetime where date='$selectdate' and code='$pcode' and flag='T'";
			$row=$db->fetch_array($db->query($sql));
			$count=$row["count"];
			?>
			<?php if($count==0){?>
			<option value="2017-10-<?php echo $dd;?>" disabled="disabled"><?php echo $d;?></option>
			<?php }else{?>
			<option value="2017-10-<?php echo $dd;?>"><?php echo $d;?></option>		
			<?php }?>
			<?php }?>
			</select>
			<span>2017年11月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
			<?php for($d=1;$d<=30;$d++){
			if($d<=9){
			$dd="0".$d;
			}else{
			$dd=$d;
			}
			?>
			<?php
			$selectdate="2017-11-".$dd;
			$sql = "select count(*) as count from ".tableprefix."datetime where date='$selectdate' and code='$pcode' and flag='T'";
			$row=$db->fetch_array($db->query($sql));
			$count=$row["count"];
			?>
			<?php if($count==0){?>
			<option value="2017-11-<?php echo $dd;?>" disabled="disabled"><?php echo $d;?></option>
			<?php }else{?>
			<option value="2017-11-<?php echo $dd;?>"><?php echo $d;?></option>		
			<?php }?>
			<?php }?>
			</select>
			<span>2017年12月</span>
			<select class="ui-choose" multiple="multiple" id="uc_04" name="posTypeSelect[]">
				<option></option>
				<option></option>
			<?php for($d=1;$d<=31;$d++){
			if($d<=9){
			$dd="0".$d;
			}else{
			$dd=$d;
			}
			?>
			<?php
			$selectdate="2017-12-".$dd;
			$sql = "select count(*) as count from ".tableprefix."datetime where date='$selectdate' and code='$pcode' and flag='T'";
			$row=$db->fetch_array($db->query($sql));
			$count=$row["count"];
			?>
			<?php if($count==0){?>
			<option value="2017-12-<?php echo $dd;?>" disabled="disabled"><?php echo $d;?></option>
			<?php }else{?>
			<option value="2017-12-<?php echo $dd;?>"><?php echo $d;?></option>		
			<?php }?>
			<?php }?>
			</select>
		</div>
	</div>
	
	<div class="order-box">
		<div class="orderinfo">
			<div class="order-info">
				<label>联系人</label>
				<input type="text" maxlength="20" id="nickname" name="nickname" placeholder="请填写联系人姓名">
			</div>
			<div class="order-info">
				<label>手机号码</label>
				<input type="text" maxlength="11" id="mobile" name="mobile" placeholder="请填写联系人手机号码">
			</div>
			<div class="order-info">
				<label>验证码</label>
				<input id="code" name="code" type="text" placeholder="请输入验证码" maxlength="4">
			    <span class="code"><img id="imgCode" src="../include/verify.php" alt="请输入验证码"></span>			
			</div>
			<div class="order-info">
				<label>动态码</label>
				<input type="text" maxlength="6" id="smscode" name="smscode" placeholder="请输入短信验证码">
				<span class="code-box"><input id="zphone" type="button" value=" 获取手机验证码 " onClick="get_mobile_code();" class="btn"></span>
			</div>
		</div>
	</div>
	
	<div class="order-box">
		<div class="payway">
			<h1>请选择支付方式</h1>
			<ul>
				<li>
					<input type="radio" name="payment" id="payment" value="wechatPay" checked>
					<img src="../images/wechatPay.jpg" />
					<label>微信支付</label>
				</li>
				<!--
				<li>
					<input type="radio" name="payment" id="payment" value="aliPay">
					<img src="../images/AliPay.jpg" />
					<label>支付宝支付</label>
				</li>
				-->
			</ul>
		</div>
	</div>	
	<div class="form-button"><input name="s" type="submit" id="s" value="提&nbsp;&nbsp;交"></div>
	<div class="form-readme"><p>我已阅读并同意<font color="#0099FF">《网演中国服务条款》</font></p></div><br>
</div>
</form>

<footer id="bar-fixed">
	<a href="index.php" class="tab-item"><i class="icon-tabbar bar-home"></i>首页</a>
	<a href="category.php" class="tab-item active"><i class="icon-tabbar bar-message2"></i>分类</a>
	<a href="publish/" class="tab-item"><i class="icon-tabbar bar-publish"></i>发布</a>	
	<a href="user/" class="tab-item"><i class="icon-tabbar bar-user"></i>我</a>
</footer>
<script src="js/src/jquery-1.11.0.min.js"></script>
<script src="js/src/ui-choose.js"></script>
<script>
	// 将所有.ui-choose实例化
	$('.ui-choose').ui_choose();
	// uc_04 select 多选
	var uc_04 = $('#uc_04').ui_choose();
	uc_04.click = function(value, item) {
	    console.log('click', value);
	};
	uc_04.change = function(value, item) {
	    console.log('change', value);
	};
</script>
</body>
</html>
<?php
$db->close();
exit;
?>